package com.tom.zojbackendquestionservice.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tom.zojbackendcommon.constant.CommonConstant;
import com.tom.zojbackendcommon.utils.SqlUtils;
import com.tom.zojbackendmodel.model.dto.questionSolution.QuestionSolutionQueryRequest;
import com.tom.zojbackendmodel.model.entity.Question;
import com.tom.zojbackendmodel.model.entity.QuestionSolution;
import com.tom.zojbackendquestionservice.mapper.QuestionSolutionMapper;
import com.tom.zojbackendquestionservice.service.QuestionSolutionService;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.stereotype.Service;


/**
* @description 针对表【question_solution(用户题解)】的数据库操作Service实现
*/
@Service
public class QuestionSolutionServiceImpl extends ServiceImpl<QuestionSolutionMapper, QuestionSolution>
    implements QuestionSolutionService {

    /**
     * 获取查询包装类
     *
     * @param solutionQueryRequest
     * @return
     */
    @Override
    public QueryWrapper<QuestionSolution> getQueryWrapper(QuestionSolutionQueryRequest solutionQueryRequest) {
        QueryWrapper<QuestionSolution> queryWrapper = new QueryWrapper<>();
        if (solutionQueryRequest == null) {
            return queryWrapper;
        }
        Long questionId = solutionQueryRequest.getQuestionId();
        Long userId = solutionQueryRequest.getUserId();
        String sortField = solutionQueryRequest.getSortField();
        String sortOrder = solutionQueryRequest.getSortOrder();


        // 拼接查询条件
        queryWrapper.eq(ObjectUtils.isNotEmpty(questionId), "questionId", questionId);
        queryWrapper.eq(ObjectUtils.isNotEmpty(userId), "userId", userId);
        queryWrapper.orderBy(SqlUtils.validSortField(sortField), sortOrder.equals(CommonConstant.SORT_ORDER_ASC),
                sortField);
        return queryWrapper;
    }

}




